package cn.itcast.controller;


import cn.itcast.domain.Standard;

import cn.itcast.service.StandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class StandardController {

    //调用service
    @Autowired
    private StandardService standardService;


    //用户添加
    @RequestMapping("/standard_save")
    public  String save(Standard standard){
        standardService.save(standard);
        //这里不能用转发 只能用重定向
        return "redirect:/pages/base/standard.html";



    }

    /**
     * 用户添加
     * @param page
     * @param rows
     * @return
     */
  @RequestMapping("/standard_pageQuery")
  @ResponseBody
    public Map pageQuery(int page,int rows){
      Page<Standard> pageResult=  standardService.pageQuery(page ,rows);
      Map<String,Object> result=new HashMap<String,Object>();
        result.put("total",pageResult.getTotalElements());
         result.put("rows",pageResult.getContent());
        System.out.println(result.toString());
      return result;
    }

  @RequestMapping("/standard_findAll")
    @ResponseBody
  public List<Standard>findAll(){


      return  standardService.findAll();
  }



}
